generate codacy coverage report on travis (#195)
authortsteven4 <tsteven4@users.noreply.github.com>
Sun, 17 Jun 2018 03:46:46 +0000 (21:46 -0600)
committerGitHub <noreply@github.com>
Sun, 17 Jun 2018 03:46:46 +0000 (21:46 -0600)
.travis.yml
GPSBabel.pro
tools/Dockerfile
tools/qtci/README.gpsbabel
tools/qtci/install-qt [new file with mode: 0755]
tools/travis_install_linux_coverage [new file with mode: 0755]
tools/travis_script_linux_coverage [new file with mode: 0755]
tools/travis_script_osx
tools/travis_tokens [new file with mode: 0755]

index 609ea8a25c3c43f32514a0c02f3957858dc0243a..2aac059ce6b4c1699846e191dce497dfb0df4585 100644 (file)
@@ -17,12 +17,28 @@ matrix:
       cache:
         directories:
           - $HOME/Qt
+    - os: linux
+      dist: trusty
+      sudo: required
+      compiler: gcc
+      env:
+        - GEN_COVERAGE="true"
+      addons:
+        apt:
+          packages:
+            - libusb-dev
+            - gcovr
+      cache:
+        directories:
+          - $HOME/Qt
 
 install:
   - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then source ./tools/travis_install_osx; fi
+  - if [ "${TRAVIS_OS_NAME}" = "linux" ] && [ "${GEN_COVERAGE}" = "true" ]; then ./tools/travis_install_linux_coverage; fi 
 
 script:
-  - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./tools/travis_script_linux_docker; fi 
+  - if [ "${TRAVIS_OS_NAME}" = "linux" ] && [ "${GEN_COVERAGE}" != "true" ]; then ./tools/travis_script_linux_docker; fi 
+  - if [ "${TRAVIS_OS_NAME}" = "linux" ] && [ "${GEN_COVERAGE}" = "true" ]; then ./tools/travis_script_linux_coverage; fi 
   - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ./tools/travis_script_osx; fi
 
 after_success:
index 4a5cb2dfc339e2bd3ba6d1b26ebbdf64241e3060..10a074b21958c48dc384de9a016334aa4ca1eec4 100644 (file)
@@ -223,3 +223,21 @@ linux{
 clang-tidy.commands = run-clang-tidy.py $(RUN_CLANG_TIDY_FLAGS)
 clang-tidy.depends = compile_commands.json
 QMAKE_EXTRA_TARGETS += clang-tidy
+
+# generate coverage report for codacy
+# must use gcc, g++
+# the upload requires CODACY_PROJECT_TOKEN be set.
+# dependencies:
+# wget https://oss.sonatype.org/service/local/repositories/releases/content/com/codacy/codacy-coverage-reporter/4.0.1/codacy-coverage-reporter-4.0.1-assembly.jar
+# extra ubuntu bionic packages: gcovr, openjdk-8-jre-headless, /usr/lib/jvm/java-8-openjdk-amd64/bin/java
+# as of 6/18/2018 you must use java 8, see issue #76, #83 at https://github.com/codacy/codacy-coverage-reporter/issues
+linux{
+  coverage.commands = make clean;
+  coverage.commands += ln -sf GPSBabel gpsbabel;
+  coverage.commands += $(MAKE) CFLAGS=\"$(CFLAGS) -fprofile-arcs -ftest-coverage\" CXXFLAGS=\"$(CXXFLAGS) -fprofile-arcs -ftest-coverage\" LFLAGS=\"$(LFLAGS) --coverage\" &&
+  coverage.commands += ./testo &&
+  coverage.commands += gcov -r $(SOURCES) &&
+  coverage.commands += gcovr -r . --xml --exclude='zlib/*' --exclude='shapelib/*' -o gpsbabel_coverage.xml &&
+  coverage.commands += java -jar codacy-coverage-reporter-4.0.1-assembly.jar report -l cpp -f -r gpsbabel_coverage.xml
+  QMAKE_EXTRA_TARGETS += coverage
+}
index 5a09bb2115f592d2b57139fff265f2cb6a5374b5..4ac496a3d0cf453d74499a87b46a818ef51fa962 100644 (file)
@@ -15,6 +15,8 @@ RUN apt-get install -y clang
 RUN apt-get install -y expat fop xsltproc libxml2-utils docbook-xml docbook-xsl
 RUN apt-get install -y libusb-dev
 RUN apt-get install -y qt5-default libqt5webkit5-dev qttools5-dev-tools
+# pkgs needed to generate coverage report:
+RUN apt-get install -y gcovr openjdk-8-jre-headless
 
 # install environment for locale test
 RUN apt-get install -y locales && sed -i 's/^# *\(en_US ISO-8859-1\)/\1/' /etc/locale.gen && locale-gen && locale -a
index 8875a0c371997805561f79a30c79cd91b7114e82..a4bc8393fddd5706591b2c8ac997af9d5399288e 100644 (file)
@@ -1 +1 @@
-The files extract-qt-installer, LICENSE, qt-5.9.5-osx, and README.md are from https://github.com/benlau/qtci
+The files extract-qt-installer, install-qt, LICENSE, qt-5.9.5-osx, and README.md are from https://github.com/benlau/qtci
diff --git a/tools/qtci/install-qt b/tools/qtci/install-qt
new file mode 100755 (executable)
index 0000000..7339860
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+#QT_VERSION=5.10.0
+
+QT_VERSION=$1
+echo Downloading Qt
+wget -nv -c  https://download.qt.io/archive/qt/$(echo $1 |cut -d "." -f-2)/${QT_VERSION}/qt-opensource-linux-x64-${QT_VERSION}.run
+INSTALLER=qt-opensource-linux-x64-${QT_VERSION}.run
+ENVFILE=qt-${QT_VERSION}.env
+echo Installing Qt
+
+
+extract-qt-installer $PWD/$INSTALLER $PWD/Qt
+
+echo Create $ENVFILE
+cat << EOF > $ENVFILE
+export PATH=$PWD/Qt/${QT_VERSION}/gcc_64/bin:$PATH
+EOF
diff --git a/tools/travis_install_linux_coverage b/tools/travis_install_linux_coverage
new file mode 100755 (executable)
index 0000000..8c0cdde
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash -ex
+#
+# This script is run on travis for the install stage of mac builds.
+# Note the script must be sourced if you want the modified PATH to
+# be used outside this script.
+#
+
+# our expectation is that install-qt creates $QTDIR, $QTDIR/bin.
+QTDIR=${HOME}/Qt/5.7/gcc_64
+
+if [ -d "${QTDIR}/bin" ]; then
+  echo "Using cached Qt."
+  echo "If you need to clear the cache see"
+  echo "https://docs.travis-ci.com/user/caching/#Fetching-and-storing-caches."
+else
+  pushd ${HOME};
+  rm -fr Qt
+  # install_qt creates the install at $PWD/Qt.
+  QT_CI_PACKAGES=qt.57.gcc_64 PATH=${TRAVIS_BUILD_DIR}/tools/qtci:${PATH} install-qt 5.7.1
+  popd;
+fi
+# note that qt-5.7.1.env created by install-qt is not cached!
+export PATH=${QTDIR}/bin:${PATH}
+unset -v QTDIR
diff --git a/tools/travis_script_linux_coverage b/tools/travis_script_linux_coverage
new file mode 100755 (executable)
index 0000000..82875c7
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash -ex
+#
+# generate coverage report and upload to codacy
+which qmake
+export PATH=${HOME}/Qt/5.7/gcc_64/bin:$PATH
+which qmake
+
+# debug tokens
+"$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"/travis_tokens
+
+wget -nv -c https://oss.sonatype.org/service/local/repositories/releases/content/com/codacy/codacy-coverage-reporter/4.0.1/codacy-coverage-reporter-4.0.1-assembly.jar
+qmake
+make coverage
+
index 1272928c5cebaf8c6b18e987d57b733343f080cf..3e13b0a27ab908f19587886646089ec76b6915f5 100755 (executable)
@@ -10,6 +10,9 @@ MACDEPLOYQT=${MACDEPLOYQT:-macdeployqt}
 # we assume we are on macOS, so date is not gnu date.
 VERSIONID=${VERSIONID:-$(date -ju -f %Y-%m-%dT%H:%M:%S%z $(git show -s --format="%aI" HEAD | sed 's/:\(..\)$/\1/') +%Y%m%dT%H%MZ)-$(git rev-parse --short=7 HEAD)}
 
+# debug tokens
+"$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"/travis_tokens
+
 # build and test the CLI
 $QMAKE GPSBabel.pro && make && make check
 
diff --git a/tools/travis_tokens b/tools/travis_tokens
new file mode 100755 (executable)
index 0000000..15e8f79
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash -e
+
+# dont leak unhashed tokens!
+set +x
+if [ ! -z "${CODACY_PROJECT_TOKEN+x}" ] ; then
+  if which sha512sum; then
+    echo -n "CODACY_PROJECT_TOKEN hash: "
+    echo $CODACY_PROJECT_TOKEN | sha512sum
+  else
+    echo CODACY_PROJECT_TOKEN hash unknown.
+  fi
+else
+  echo CODACY_PROJECT_TOKEN not set.
+fi
+if [ ! -z "${GITHUB_TOKEN+x}" ] ; then
+  if which sha512sum; then
+    echo -n "GITHUB_TOKEN hash: "
+    echo $GITHUB_TOKEN | sha512sum
+  else
+    echo GITHUB_TOKEN hash unknown.
+  fi
+else
+  echo GITHUB_TOKEN not set.
+fi
+set -x